package com.yuanduo_app.db.waterdb

import com.xujl.fastlib.utils.JsonUtil
import com.yuanduo_app.bridge.DataModule
import com.yuanduo_app.consts.RNEvent
import com.yuanduo_app.manager.RNModuleManager
import com.yuanduo_app.utils.DeviceUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 * versions:
 * coding by pmj on 2021/8/10
 * desc:
 */
object WaterUtils {

    fun checkWaterData() {
        GlobalScope.launch {
            var isUpload = false
            withContext(Dispatchers.IO) {
                var list = waterDB.waterDao().getAll()
                if (list.isNullOrEmpty()) {
                    return@withContext
                }

                if (DeviceUtils.getNetIp().isNullOrEmpty()) {
                    return@withContext
                }
                isUpload = true
            }
            if (isUpload) {
                RNModuleManager.getInstance().getModule(DataModule::class.java)
                    ?.sendEvent(RNEvent.APP_NET_CONNECT, "")
            }
        }
    }

}